package ink.ykb.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

/**
 * 错误码工具类
 * @author mading
 *
 */
@Component
public class MessageUtil {
  
  @Autowired
  private MessageSource messageSource;
  
  /**
   * 根据code获取对应国际化文件信息
   * @param code
   * @return
   */
  public String getMsg(String code) {
      return messageSource.getMessage(code, new Object[] {}, LocaleContextHolder.getLocale());
  }
  
  /**
   * 根据code获取对应国际化文件信息 支持占位符
   * @param code
   * @param args
   * @return
   */
  public String getMsg(String code,Object[] args) {
      return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
  }

}
